go:-bm(T),println(T).

bm(T):-bm(11,T).

bm(N,T):-ctime(T1),run_bm(N),ctime(T2),dif(T2,T1,T).

run_bm(N):-queens(N,_Qs),fail.
run_bm(_):-true.

qs(Qs):-queens(8,Qs).

queens(N,Ps):-gen_queens(N,Qs),gen_places(Qs,Ps),place_queens(Qs,Ps,_1,_2).

% at each step inc Us and dec Ds
place_queens([],_1,_2,_3).
place_queens(.(I,Is),Cs,Us,.(_,Ds)):-place_queens(Is,Cs,.(_X,Us),Ds),place_queen(I,Cs,Us,Ds).

place_queen(I,.(I,_1),.(I,_2),.(I,_3)).
place_queen(I,.(_1,Cs),.(_2,Us),.(_3,Ds)):-place_queen(I,Cs,Us,Ds).

gen_queens(Max,Qs):-range(0,Max,Qs).

gen_places([],[]).
gen_places(.(_1,Qs),.(_2,Ps)):-gen_places(Qs,Ps).


loop(X):-eq(X,Y),loop(Y).

loop:-loop(_).
